import Vue from "vue";
import Vuex from "vuex";
import api from './api'

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
  	turnoverUserContext: {},
    timeParams: {},
    areaParams: {},
    downLink: '',
    token: '',
    sideBarWidth: false
  },
  mutations: {
  	// 保存用户上下文信息
    SaveTurnoverUserContext: (state, data) => {
      state.turnoverUserContext = data
    },
    // 请求参数
    SaveTimeParams: (state, data) => {
      state.timeParams = data
    },
    // 请求参数
    SaveAreaParams: (state, data) => {
      state.areaParams = data
    },
    SaveDownLink: (state, data) => {
      state.downLink = data
    },
    SaveToken: (state, data) => {
      state.token = data.data
      window.localStorage.setItem('token', data.data.username)
    },
    SaveSideBarWidth: (state, data) => {
      state.sideBarWidth = data
    }
  },
  actions: {
    SetTimeParams({ commit }, params) {
      commit('SaveTimeParams', params)
    },
    SetAreaParams({ commit }, params) {
      commit('SaveAreaParams', params)
    },
    SetDownLink({ commit }, params) {
      commit('SaveDownLink', params)
    },
    SetSideBarWidth({ commit }, params) {
      commit('SaveSideBarWidth', params)
    },
  	// 客流数据分析
  	PassengerData ({ commit }, params) {
      return api.PassengerData(params, (res) => {
      })
    },
    // 单门店年龄性别比较
    AgeSexualStoreData ({ commit }, params) {
      return api.AgeSexualStoreData(params, (res) => {
      })
    },
    // 各分店到店性别比例
    SexualDate ({ commit }, params) {
      return api.SexualDate(params, (res) => {
      })
    },
  	// 获取用户上下文信息
    GetTurnoverUserContext ({ commit }, params) {
      return api.GetTurnoverUserContext(params, (res) => {
        commit('SaveTurnoverUserContext', res)
      })
    },
		// 获取中国地图
		ChinamapData ({ commit }, params) {
			return api.ChinamapData(params, (res) => {
			})
		},
		// 获取总流量周高峰时段
		RushHourData ({ commit }, params) {
			return api.RushHourData(params, (res) => {
			})
		},
    // 当天客流
    DayPeakPeriodData ({ commit }, params) {
      return api.DayPeakPeriodData(params, (res) => {
      })
    },
    // 当天客流
    provinceEntersData ({ commit }, params) {
      return api.provinceEntersData(params, (res) => {
      })
    },
    // 查询此用户下所有门店信息或品牌
    SearchAreas ({ commit }, params) {
      return api.SearchAreas(params, (res) => {
      })
    },
    // 查询此用户下所有门店信息或品牌
    Login ({ commit }, params) {
      return api.Login(params, (res) => {
        commit('SaveToken', res)
      })
    }
  }
});
